package com.zhaoxi.project.wms.controller;

import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.framework.web.BaseService;
import com.zhaoxi.framework.web.PageData;
import com.zhaoxi.project.wms.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 跟物品有关的订单Controller
 */
@RestController
@RequestMapping("/wms/order")
public class OrderController extends BaseService {
  @Autowired
  private OrderService orderService;

  //  获列表
  @PreAuthorize("@ss.hasPermi('wms:order:list')")
  @GetMapping("/getList")
  public PageData getList(Map map) {
    PageData pd = this.getPageData(map);
    //如果 pageNum 和 pageSize 都是有值的，就是需要分页的
    if (pd.getLong("pageNum") != null && pd.getLong("pageSize") != null){
      this.startPage();
    }
    return this.responses(orderService.getList(pd));
  }

  //  获行数
  @PreAuthorize("@ss.hasPermi('wms:order:list')")
  @GetMapping("/getCount")
  public PageData getCount(Map map) {
    PageData pd = this.getPageData(map);
    return orderService.getCount(pd);
  }

  //  新增
  @PreAuthorize("@ss.hasPermi('wms:order:add')")
  @Log(title = "样例管理", businessType = BusinessType.INSERT)
  @PostMapping
  public PageData add(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return orderService.add(pd);
  }

  //  修改
  @PreAuthorize("@ss.hasPermi('wms:order:edit')")
  @Log(title = "样例管理", businessType = BusinessType.UPDATE)
  @PutMapping
  public PageData edit(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return orderService.edit(pd);
  }

  //  删除
  @PreAuthorize("@ss.hasPermi('wms:order:del')")
  @Log(title = "样例管理", businessType = BusinessType.DELETE)
  @DeleteMapping("id/{id}")
  public PageData del(@PathVariable Long id) {
    return orderService.del(id);
  }

  //============子表数据增删改查================
  //  获列表
  @PreAuthorize("@ss.hasPermi('wms:order:list')")
  @GetMapping("/getLineList")
  public PageData getLineList(Map map) {
    PageData pd = this.getPageData(map);
    return this.responses(orderService.getLineList(pd));
  }

  //  获行数
  @PreAuthorize("@ss.hasPermi('wms:order:list')")
  @GetMapping("/getLineCount")
  public PageData getLineCount(Map map) {
    PageData pd = this.getPageData(map);
    return orderService.getLineCount(pd);
  }

  //  新增
  @PreAuthorize("@ss.hasPermi('wms:order:add')")
  @Log(title = "样例管理", businessType = BusinessType.INSERT)
  @PostMapping("/line")
  public PageData addLine(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return orderService.addLine(pd);
  }

  //  修改
  @PreAuthorize("@ss.hasPermi('wms:order:edit')")
  @Log(title = "样例管理", businessType = BusinessType.UPDATE)
  @PutMapping("/line")
  public PageData editLine(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return orderService.editLine(pd);
  }

  //  删除
  @PreAuthorize("@ss.hasPermi('wms:order:del')")
  @Log(title = "样例管理", businessType = BusinessType.DELETE)
  @DeleteMapping("lineId/{lineId}")
  public PageData delLine(@PathVariable Long lineId) {
    PageData pd = this.getPageData();
    pd.put("lineId",lineId);
    return orderService.delLine(pd);
  }


  //============type关联表数据增删改查================
  //  获列表
  @PreAuthorize("@ss.hasPermi('wms:orderType:list')")
  @GetMapping("/getTypeList")
  public PageData getTypeList(Map map) {
    PageData pd = this.getPageData(map);
    return this.responses(orderService.getTypeList(pd));
  }

  //  获行数
  @PreAuthorize("@ss.hasPermi('wms:orderType:list')")
  @GetMapping("/getTypeCount")
  public PageData getTypeCount(Map map) {
    PageData pd = this.getPageData(map);
    return orderService.getTypeCount(pd);
  }

  //  新增
  @PreAuthorize("@ss.hasPermi('wms:orderType:add')")
  @Log(title = "样例管理", businessType = BusinessType.INSERT)
  @PostMapping("/type")
  public PageData addType(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return orderService.addType(pd);
  }

  //  修改
  @PreAuthorize("@ss.hasPermi('wms:orderType:edit')")
  @Log(title = "样例管理", businessType = BusinessType.UPDATE)
  @PutMapping("/type")
  public PageData editType(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return orderService.editType(pd);
  }

  //  删除
  @PreAuthorize("@ss.hasPermi('wms:orderType:del')")
  @Log(title = "样例管理", businessType = BusinessType.DELETE)
  @DeleteMapping("typeId/{typeId}")
  public PageData delType(@PathVariable Long typeId) {
    return orderService.delType(typeId);
  }

}
